package com.beyondsoft.sabg.edu.utils;

import cn.hutool.core.date.DatePattern;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @Author Mo cr
 * @Date 2025/1/17
 */
public class DateUtils {
    /**
     * 比较年月格式的日期大小，判断是否在指定开始结束时间范围内，相同则返回true
     * @param start 2025-01
     * @param end 2025-01
     * @param compared 2025-01
     * @return
     */
    public static boolean monthBetween(String start,String end,String compared){
        if(start.equals(compared)){
            return true;
        }
        if(end.equals(compared)){
            return true;
        }
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN);
        LocalDate startDate = LocalDate.parse(start+"-01", formatter);
        LocalDate endDate = LocalDate.parse(end+"-01", formatter);
        LocalDate comparedDate = LocalDate.parse(compared+"-01", formatter);
        return comparedDate.isAfter(startDate) && comparedDate.isBefore(endDate);
    }
}
